package com.qiang.test05;


public class SellTicket implements Runnable {
    private int tickets = 100;
    //private Object o = new Object();

    @Override
    public void run() {

        String s = "sss";
        while (true) {
            synchronized (s) {
                if (tickets <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + "当前还剩下" + tickets + "张票");
                }
            }
        }
    }
}
